package net.heri.xmppchat.persistence;

import java.sql.SQLException;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper;
import com.j256.ormlite.dao.DaoManager;
import com.j256.ormlite.support.ConnectionSource;
import com.j256.ormlite.table.TableUtils;

public class XmppChatDBHelper extends OrmLiteSqliteOpenHelper implements IXmppChatDBHelper {
	
	private final String TAG = XmppChatDBHelper.class.getSimpleName();

	public XmppChatDBHelper(Context context) {
		super(context, "xmpp_chat", null, 1);
	}	

	@Override
	public void onCreate(SQLiteDatabase arg0, ConnectionSource arg1) {
		
		Log.i(TAG, "onCreate()");
		
		try {
			TableUtils.createTableIfNotExists(connectionSource, ChatSession.class);
		} catch (SQLException e) {			
			e.printStackTrace();
		}
	}

	@Override
	public void onUpgrade(SQLiteDatabase arg0, ConnectionSource arg1, int arg2,	int arg3) {
		
	}
	
	public ChatSessionDao getChatSessionDao() throws SQLException {
		return DaoManager.createDao(connectionSource, ChatSession.class);
	}

}
